package com.sicheng.lc.lc笔试.字节篇;

import java.util.Scanner;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/5/23 20:34
 */
public class 序列中第一个未出现的正整数 {


    public static void main(String[] args) {
        //要求时间复杂度O(n)  空间复杂度O(1)
        // 6
        // -6 2 1 6 8 3
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }

        for (int i = 0; i < n; i++) {
            while (nums[i] != i && nums[i] > 0 && nums[i] < n) {
                int temp = nums[nums[i]];
                nums[nums[i]] = nums[i];
                nums[i] = temp;
            }
        }

        for (int i = 1; i < n; i++) {
            if (nums[i] != i) {
                System.out.println(i);
                break;
            }
        }
    }

}
